﻿using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;

namespace CMS.Common.Validation
{
    public class PhoneAttribute : RegularExpressionAttribute, IClientValidatable
    {
        public PhoneAttribute()
            : base(@"^\(\d{3}\)\s\d{3}\-\d{4}$")
        {
        }

        public System.Collections.Generic.IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
        {
            var rule = new ModelClientValidationRegexRule(ErrorMessage, Pattern);
            rule.ErrorMessage = FormatErrorMessage(metadata.GetDisplayName());
            return new[] { rule };
        }
    }
}